import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout'

// import { getUserInfo } from '@/utils/auth'
// import { formatMenus } from '@/utils/menu'
import congigRouter from './config'

Vue.use(Router)

const commonRouter = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
    meta: { name: '登录' }
  },
  {
    path: '/test',
    component: () => import('@/views/test'),
    hidden: true
  },
  {
    path: '/home',
    component: Layout,
    children: [
      {
        path: '/home/index',
        component: () => import('@/views/home/index')
      }
    ]
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  }
]

const createRouter = () =>
  new Router({
    mode: 'history',
    scrollBehavior: () => ({ y: 0 }),
    routes: [...commonRouter, ...congigRouter]
  })

const router = createRouter()
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
